package org.stratusdb.funsql.compile.operator;

import java.util.HashMap;

import org.stratusdb.funsql.compile.tokens.TokenAttribute;
import org.stratusdb.funsql.compile.tokens.AbstractToken;

public class EquiSelection extends AbstractUnaryOperator {
	private static final long serialVersionUID = 5178586492851005421L;
	
	private TokenAttribute attribtue;
	private AbstractToken value;
	
	private HashMap<TokenAttribute,AbstractToken> predList = new HashMap<TokenAttribute,AbstractToken>();
	
	//constructors
	public EquiSelection(AbstractOperator child) {
		super(child);
		this.type = EnumOperator.EQUI_SELECTION;
	}

	//getters and setters
	public TokenAttribute getAttribtue() {
		return attribtue;
	}

	public void setAttribtue(TokenAttribute attribtue) {
		this.attribtue = attribtue;
	}

	public AbstractToken getValue() {
		return value;
	}

	public void setValue(AbstractToken value) {
		this.value = value;
	}
	
	public void addPredicate(TokenAttribute attribute, AbstractToken value) {
		this.predList.put(attribute, value);
	}
	
	public HashMap<TokenAttribute,AbstractToken> getPredicates() {
		return (HashMap<TokenAttribute,AbstractToken>) this.predList.clone();
	}
	
	public String toString() {
		StringBuffer str = new StringBuffer(((this.getConnection()==null)?"null":this.getConnection().getUrl()) +" : "
				+ this.getType() +" : " + this.getColumns().size() + " : " + this.getColumns() + " : ");
		if(this.predList.isEmpty()) {
			str.append(this.getAttribtue().toSqlString() + " = " + this.getValue().toSqlString());
		}
		else {
			for(TokenAttribute key: this.predList.keySet()){
				str.append( " " + key + " = " + this.predList.get(key)); 
			}
		}
		return str.toString();
	}
}
